import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import path from "path"
import AutoImport from "unplugin-auto-import/vite"
import Components from "unplugin-vue-components/vite"
import { ElementPlusResolver } from "unplugin-vue-components/resolvers"
import ElementPlus from "unplugin-element-plus/vite"

import UnoCss from "unocss/vite"

// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: [
      {
        find: "@",
        replacement: path.resolve(__dirname, "./src")
      }
    ]
  },
  plugins: [
    vue(),
    UnoCss(),
    AutoImport({
      // 解析api
      // 并在项目下生成 auto-imports.d.ts 文件，防止ts报错
      imports: ["vue", "vue-router", "pinia"],
      resolvers: [ElementPlusResolver()],
      eslintrc: { enabled: false } // 改成true⽣成⼀次后禁⽤即可
    }),
    Components({
      // 解析组件
      resolvers: [ElementPlusResolver()],
      // 所有的组件可以自动加载， 不需要import就可以使用
      // 并在项目下生成 components.d.ts 文件，防止ts报错
      dirs: ["src/components", "src/layout/components"]
    }),
    ElementPlus({})
  ]
})
